// Device/pages/HistoryInfo/components/glucometer-component/index.js
const app = getApp();
import {
    customNavigate
} from '@/utils/route'
import {
    logger
} from '@/utils/util'
const typeMappings = {
    '餐前': 'glu_',
    '餐后': 'pbg_'
}
const userMappings = {
    '本人': '_self',
    '配偶': '_mate',
    '子女': '_sons',
    '其他': '_other'
}
Component({
    properties: {
        params: {
            type: Object,
            default: null
        },
        data: {
            type: Object,
            default: null
        }
    },
    observers: {
        params(value) {
            const {
                blood_glucose_val,
                measuring_time,
                user_tag,
                measurement_type
            } = value;
            let min = this.data.data[`${typeMappings[value['measurement_type']]}min${userMappings[value['user_tag']]}`],
                max = this.data.data[`${typeMappings[value['measurement_type']]}max${userMappings[value['user_tag']]}`];
            this.setData({
                min,
                max,
                measuring_time,
                user_tag,
                measurement_type,
                blood_glucose_val,
                state: blood_glucose_val < min ? '低血糖异常' : blood_glucose_val > max ? '高血糖异常' : '正常血糖'
            })
        }
    },
    data: {
        staticPrefix: app.globalData.STATIC_PREFIX,
        min: 0,
        max: 0,
        state: null,
        measuring_time: null,
        user_tag: null
    },
    methods: {
        onNavigateToAnalysis() {
            const params = {
                device_imei: this.data.params.device_imei
            }
            customNavigate({
                url: '/Device/pages/Analysis/index',
                params
            })
        }
    }
})